import { ElNotification,ElMessage,ElMessageBox ,ElLoading } from 'element-plus'
export const msg = (message,type = 'success')=>{
    ElNotification({
        message:message,
        type:type ,
        duration:2000
      })
}

export const message = (message,type='success')=>{
  ElMessage({
    message:message,
    type:type ,
  })
}
export const messageBox = async (title = '確認是否刪除',confirm='確認',cancel='取消',type='warning')=>{
 await ElMessageBox.confirm(title,{
    confirmButtonText: confirm,
    cancelButtonText: cancel,
    type: type,
  })
}
const options = {
  lock: true,
  text: 'Loading',
  // fullscreen: true,
  background: 'rgba(0, 0, 0, 0.7)',
  // target: '.right-container' // target指定需要覆盖的 DOM 节点，会获取到问的那个中第一个类名为right-container的元素
}
let loadingInstance;
export const loading = async ()=>{
  loadingInstance = ElLoading.service(options)
 }
 export const closeLoading = async ()=>{
  loadingInstance.close()
 }
 export const loadings = async ()=>{
  loadingInstance = ElLoading.service({ fullscreen: true })
 }

 export const getTime = (type) => {
  /*
   * type:时间显示模式.若传入12则为12小时制,不传入则为24小时制
   */
  //年月日时分秒
  var Y, M, D, W, H, I, S;
  //月日时分秒为单位时前面补零
  function fillZero(v) {
    if (v < 10) {
      v = '0' + v;
    }
    return v;
  }
  // (function() {
  var d = new Date();
  var Week = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  var nowRegion = ''
  Y = d.getFullYear();
  M = fillZero(d.getMonth() + 1);
  D = fillZero(d.getDate());
  W = Week[d.getDay()];
  H = fillZero(d.getHours());
  I = fillZero(d.getMinutes());
  S = fillZero(d.getSeconds());
  //12小时制显示模式
  if (type && type == 12) {
    //若要显示更多时间类型诸如中午凌晨可在下面添加判断
    if (H <= 12) {
      H = H
      nowRegion = '上午'
    } else if (H > 12 && H < 18) {
      H -= 12
      H = fillZero(H)
      nowRegion = '下午'
    } else if (H == 24) {
      H = '00'
      nowRegion = '下午'
    }
  }
  // //每秒更新时间
  // setTimeout(arguments.callee, 1000);
  // Y + '年' + M + '月' + D + '日 ' + ' ' + W + ' ' + H + ':' + I + ':' + S
  return {
    nowDate: Y + '-' + M + '-' + D,
    nowTime: H + ':' + I + ':' + S,
    nowRegion: nowRegion,
    nowWeek: W
  }
  // })()
}



